//====================================================================================================
// Filename:	PlaybackSystem.cpp
// Created by:	Peter Chan
//====================================================================================================

//====================================================================================================
// Includes
//====================================================================================================

#include "PlaybackSystem.h"

//====================================================================================================
// Class Definitions
//====================================================================================================

PlaybackSystem::PlaybackSystem()
	: mCurrentFrame(0)
	, mCapture(true)
{
}

//----------------------------------------------------------------------------------------------------

PlaybackSystem::~PlaybackSystem()
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

void PlaybackSystem::Reset(bool capture)
{
	mCurrentFrame = 0;
	mCapture = capture;
}
//----------------------------------------------------------------------------------------------------

void PlaybackSystem::BeginFrame()
{
	if (mCapture)
	{
		mCurrentFrameData.keys.clear();
	}
}

//----------------------------------------------------------------------------------------------------

void PlaybackSystem::EndFrame()
{
	if (mCapture)
	{
		mFrameData.push_back(mCurrentFrameData);
	}
	++mCurrentFrame;
}

//----------------------------------------------------------------------------------------------------

void PlaybackSystem::RecordKey(int key)
{
	mCurrentFrameData.keys.push_back(key);
}

//----------------------------------------------------------------------------------------------------

bool PlaybackSystem::IsCapturing() const
{
	return mCapture;
}

//----------------------------------------------------------------------------------------------------

bool PlaybackSystem::IsKeyPressed(int key)
{
	if (mCurrentFrame < (int)mFrameData.size())
	{
		FrameData& data = mFrameData[mCurrentFrame];
		for (int i = 0; i < (int)data.keys.size(); ++i)
		{
			if (data.keys[i] == key)
			{
				return true;
			}
		}
	}
	return false;
}
